package com.dididoctor.doctor.Activity.Usercentre.Setting.FeedBack;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.dididoctor.doctor.MV.EduActivity;
import com.dididoctor.doctor.R;
import com.dididoctor.doctor.Utils.Util;


/**
 * Created by Administrator on 2016/4/14.
 */
public class FeedBackActivity extends EduActivity implements FeedBackView {
    private TextView mTvFeedBack, mTvFinish;
    private EditText mEtFeedBack;
    private FeedBackPresenter presenter;

    private String context = "";

    @Override
    public void init() {
        setText(R.id.tv_title, "意见与反馈");
        mTvFeedBack = (TextView) findViewById(R.id.tv_feedback);
        mEtFeedBack = (EditText) findViewById(R.id.et_feedback);
        mEtFeedBack.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                mTvFeedBack.setText(Util.toString(s.length()));
            }
        });
        mTvFinish = (TextView) findViewById(R.id.tv_finish);
        mTvFinish.setVisibility(View.VISIBLE);
        mTvFinish.setText("保存");
        mTvFinish.setOnClickListener(this);

        presenter = new FeedBackPresenter(this, this);
    }

    @Override
    public void onClickEvent(View view) {
        switch (view.getId()) {
            case R.id.tv_finish:
                context = mEtFeedBack.getText().toString();
                if (Util.isEmpty(context)) {
                    showToastMessage("请填写评价");
                } else {
                    presenter.feedback(context);
                }
                break;
        }
    }

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_feedback);
    }

    @Override
    public void backSucced() {
        showToastMessage("提交成功");
        finish();
    }

    @Override
    public void backfail() {
        showToastMessage("提交失败");
    }
}
